Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ExcelLoader = undefined;
var BundleConfig = require("AA_BundleConfig");
var GameConfig = require("AA_GameConfig");
var LogManager = require("AA_LogManager");
var ResLoader = require("AA_ResLoader");
var ExcelData = require("AA_ExcelData");
var ExcelLoader = function () {
  function _creator() {}
  _creator.loadAll = function () {
    var e = this;
    return new Promise(function (t) {
      e._allFiles = JSON.parse(JSON.stringify(ExcelData.ExcelData.allFiles));
      e._totalCount = e._allFiles.length;
      var o = setInterval(function () {
        return __awaiter(e, undefined, undefined, function () {
          var e;
          return __generator(this, function () {
            if (this._loadedCount >= this._totalCount) {
              clearInterval(o);
              LogManager.LogMgr.debug("load excel done", this._totalCount);
              t(true);
            } else {
              e = this._allFiles.pop();
              if (e) {
                this.load(e);
              }
            }
            return [2];
          });
        });
      }, 1);
    });
  };
  _creator.load = function (e) {
    var t = this;
    var o = GameConfig.default.appConfig.RemoteUrl;
    if (o) {
      var n = o + GameConfig.default.appConfig.Version + "/excel/" + e + ".json?" + new Date().getTime();
      ResLoader.default.loadRemote(n, {
        ext: ".json"
      }).then(function (o) {
        ++t._loadedCount;
        if (o) {
          ExcelData.ExcelData.loadConfig(e, o);
        } else {
          console.error("load excel " + e + " error");
        }
        o.decRef();
      });
    } else {
      ResLoader.default.loadRes(BundleConfig.BundleNames.Excel, 'excel/'+e, cc.JsonAsset).then(function (o) {
        ++t._loadedCount;
        if (o) {
          ExcelData.ExcelData.loadConfig(e, o);
        } else {
          console.error("load excel " + e + " error");
        }
        o.decRef();
      });
    }
  };
  _creator._allFiles = [];
  _creator._totalCount = 0;
  _creator._loadedCount = 0;
  return _creator;
}();
exports.ExcelLoader = ExcelLoader;